<template>
  <el-dialog
    :model-value="visible"
    title="原因"
    width="600"
    :close-on-click-modal="false"
    @close="cls"
  >
    <el-form
      ref="formRel"
      :model="form"
      :rules="rules"
      label-width="120px"
      style="max-width: 800px"
    >
      <el-form-item label="原因">
        <el-input v-model="resultdata.result" />
      </el-form-item>

      <div>
        <el-button type="primary" @click="savefrom">保存</el-button>
        <el-button type="default" @click="cls">取消</el-button>
      </div>

      <!-- Add other fields similarly -->
    </el-form>
  </el-dialog>
</template>

<script setup>
import { ref } from "vue";
import { ElMessage } from "element-plus";
import { updateResult, updateStatus } from "@/api/audit.js";

const resultdata = ref({
  id: 0,
  result: ""
});
const statusdata = ref({
  id: 0,
  status: 2
});
async function savefrom() {
  let res = await updateResult(resultdata.value);
  let re = await updateStatus(statusdata.value);

  if (res.code == 200 && re.code == 200) {
    ElMessage({
      message: "已驳回",
      type: "success"
    });
    emits("refresh");
    cls();
  }

  //刷新部门列表
  // emits("refresh");
  // cls();
}

const emits = defineEmits(["close", "refresh"]);

function cls() {
  emits("close");
}
async function init(id) {
  resultdata.value.id = id;
  statusdata.value.id = id;
}
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
});

defineExpose({ init });
</script>
